#include<bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
int n;
struct xinxi {
	int cz;
	int ly;
	int czt;
} a[Maxn];
int main() {
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i].ly;
	int sum=n,lastd=0,lastt=0;
	while(1) {
		for(int i=1; i<=n; i++)
			if(a[i].cz==0) {
				int numbers=0;
				for(int j=i-1; j>=1; j--)
					if(a[j].cz==0) {
						if(a[j].ly!=a[i].ly) numbers=1;
						else numbers=2;
						break;
					}
				if(numbers<2) {
					a[i].czt=1;
					cout<<i<<" ";
					sum--;
				}
				if(a[i].czt==0&&a[i].ly==0) lastd=i;
				if(a[i].czt==0&&a[i].ly==1) lastt=i;
			}
		for(int i=1; i<=n; i++)
			a[i].cz=a[i].czt;
		if(sum==2&&a[lastd].cz==0!=0&&a[lastt].cz==0) {
			cout<<endl<<min(lastt,lastd)<<" "<<max(lastt,lastd);
			break;
		}
		if(sum==1) {
			cout<<endl;
			if(a[lastd].cz==0) cout<<lastd;
			else cout<<lastt;
			break;
		}
		cout<<endl;
	}
	return 0;
}
